﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ErhuBlog.IRepository;
using ErhuBlog.IService;
using ErhuBlog.Repository;

namespace ErhuBlog.Service
{
    public class BaseService<TEntity> : IBaseServices<TEntity> where TEntity : class

    {
        public IBaseRepository<TEntity> baseDal = new BaseRepository<TEntity>();
        void IBaseServices<TEntity>.Add(TEntity model)
        {
            baseDal.Add(model);
        }

        void IBaseServices<TEntity>.Delete(TEntity model, bool isadded)
        {
            baseDal.Delete(model, isadded);
        }

        void IBaseServices<TEntity>.Edit(TEntity model, string[] propertys)
        {
            baseDal.Edit(model, propertys);
        }

        void IBaseServices<TEntity>.Edit(TEntity model)
        {
            baseDal.Edit(model);
        }

        List<TEntity> IBaseServices<TEntity>.QueryByPage<Tkey>(int pageIndex, int pagesize, out int rowcount, Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, Tkey>> keySelector, bool IsQueryOrderBy)
        {
            return baseDal.QueryByPage(pageIndex, pagesize, out rowcount, predicate, keySelector, IsQueryOrderBy);
        }

        List<TEntity> IBaseServices<TEntity>.QueryJoin(Expression<Func<TEntity, bool>> predicate, string[] tableNames)
        {
            return baseDal.QueryJoin(predicate, tableNames);
        }

        List<TEntity> IBaseServices<TEntity>.QueryOrderBy<Tkey>(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, Tkey>> keySelector, bool IsQueryOrderBy)
        {
            return baseDal.QueryOrderBy(predicate, keySelector, IsQueryOrderBy);
        }

        List<TEntity> IBaseServices<TEntity>.QueryWhere(Expression<Func<TEntity, bool>> predicate)
        {
            return baseDal.QueryWhere(predicate);
        }

        List<TResult> IBaseServices<TEntity>.RunProc<TResult>(string sql, params object[] pamrs)
        {
            return baseDal.RunProc<TResult>(sql, pamrs);
        }

        int IBaseServices<TEntity>.SaveChanges()
        {
            return baseDal.SaveChanges();
        }
    }
}
